package com.itcast.consumer.controller;

import com.itcast.common.model.dto.request.MemberLoginReqDTO;
import com.itcast.common.model.dto.request.WechatLoginReqDTO;
import com.itcast.common.model.dto.response.LoginResDTO;
import com.itcast.security.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author itcast
 */
@RestController
@RequestMapping("/open/consumer/login")
@Api(tags = "用户端白名单接口 - 登录相关接口")
public class LoginController {
    @Resource
    private ILoginService loginService;

    @PostMapping("/sendCode")
    @ApiOperation("发送登录验证码")
    public void sendCode(@RequestParam("phone") String phone) {
        loginService.sendCode(phone);
    }

    @PostMapping
    @ApiOperation("普通用户登录")
    public LoginResDTO userLogin(@RequestBody MemberLoginReqDTO memberLoginReqDTO) {
        return loginService.memberLogin(memberLoginReqDTO);
    }

    @PostMapping("/wechat")
    @ApiOperation("普通用户微信登录")
    public LoginResDTO wechatLogin(@RequestBody WechatLoginReqDTO wechatLoginReqDTO) {
        return loginService.wechatLogin(wechatLoginReqDTO);
    }
}
